package com.hlz.rabbit.mq.wokerqueue;

import com.hlz.rabbit.mq.util.RabbitMqUtils;
import com.rabbitmq.client.CancelCallback;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;
import com.rabbitmq.client.Delivery;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * 消费线程
 *
 * @author Hongliang Zhu
 * @create 2022-11-20 15:58
 */
public class Worker01 {
    public static void main(String[] args) throws IOException, TimeoutException {
        Channel channel = RabbitMqUtils.getChannel();
        channel.basicConsume("work-queue", true, new DeliverCallback() {
            @Override
            public void handle(String consumerTag, Delivery message) throws IOException {
                System.out.println("receive a message: " + new String(message.getBody()));
            }
        }, new CancelCallback() {
            @Override
            public void handle(String consumerTag) throws IOException {
                System.out.println(consumerTag + " cancel message");
            }
        });

        System.out.println("worker consumer waiting for message form queue named hello");
    }
}
